//
//  ProductStepView.swift
//  NyamanDana
//
//  Created by 李永彬 on 2025/10/28.
//

import SwiftUI

struct ProductStepView: View {
    let stepNumber: String
    let title: String
    let description: String
    let actionButton: AnyView?
    let showDashLine: Bool
    
    init(
        stepNumber: String,
        title: String,
        description: String,
        showDashLine: Bool,
        actionButton: (() -> AnyView)? = nil
    ) {
        self.stepNumber = stepNumber
        self.title = title
        self.description = description
        self.showDashLine = showDashLine
        self.actionButton = actionButton?()
    }
    
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            // 标题部分
            HStack {
                Text(stepNumber)
                    .foregroundColor(Color(hex: "#FD632B"))
                    .font(.system(size: 14, weight: .bold))
                    .padding(.trailing, 8)
                
                Text(title)
                    .foregroundColor(Color(hex: "#271F24"))
                    .font(.system(size: 14, weight: .semibold))
            }
            .padding(.horizontal, 24)
            .padding(.vertical, 12)
            .background(Color(hex: "#FFFFFF"))
            .clipShape(Capsule())
            
            HStack(spacing: 10) {
                Spacer(minLength: 22)
                VerticalDashedLine(color: Color(hex: "#FD632B"),
                                   lineWidth: 1,
                                   dash: [3, 3])
                .frame(width: 1)
                .opacity(showDashLine ? 1 : 0)
                
                VStack {
                    Spacer(minLength: 10)
                    VStack(alignment: .leading) {
                        Spacer()
                        // 描述文本
                        Text(description)
                            .frame(maxWidth: .infinity, alignment: .leading)
                            .foregroundColor(.secondary)
                            .fixedSize(horizontal: false, vertical: true)
                        
                        // 动态按钮（如果有）
                        if let button = actionButton {
                            button
                                .padding(.top, 8)
                        }
                        Spacer()
                    }
                    .frame(maxWidth: .infinity)
                    .padding(.horizontal, 10)
                    .background(Color(hex: "#FFEDE6"))
                    .cornerRadius(12)
 
                    Spacer(minLength: 15)
                }
            }
        }
        .padding(.horizontal, 16)
    }
}
